<template>
    <div class="gongshi">
        <div>
            本界面只编辑某一个挂牌价的公式。
            【增加公式小节】可以增加公式单元，每个判断语句以【开始】开头，以【则】结束，【则】后面编写价格计算方式，可使用+,-,*,/,%（取余）,(,),数字.toFix(小数位数),等符号。变量可以使用 “基准价”和各指标名称。
        </div>
        <el-button v-on:click="AddGs">增加公式小节</el-button>
        <div v-for="(gs,index) in gongshis">
            <el-row>
                <el-col :span="4">
                    <el-select v-model="gs.append" placeholder="行关系">
                        <el-option
                        v-for="item in append_gongshi_rel"
                        :key="item"
                        :label="item"
                        :value="item">
                        </el-option>
                    </el-select>
                </el-col>
                <el-col v-if="gs.append=='则扣价'" :span="16">
                    <el-input v-model="gs.express" style="margin-left:15px;margin-right:15px;">
                        <template slot="prepend">单价=</template>
                    </el-input>
                </el-col>
                <el-col v-if="gs.append=='则扣重'" :span="16">
                    <el-input v-model="gs.express" style="margin-left:15px;margin-right:15px;">
                        <template slot="prepend">扣重=</template>
                    </el-input>
                </el-col>
                <el-col v-if="gs.append=='则拒收'" :span="16">
                </el-col>
                <el-col v-if="gs.append!=null && gs.append.indexOf('则')!=0" :span="6">
                        <el-select v-model="gs.zhibiao" placeholder="指标">
                            <el-option
                            v-for="item in zhibiaos"
                            :key="item"
                            :label="item"
                            :value="item">
                            </el-option>
                        </el-select>
                </el-col>
                <el-col v-if="gs.append!=null && gs.append.indexOf('则')!=0" :span="4">
                        <el-select v-model="gs.rel" placeholder="关系符">
                            <el-option
                            v-for="item in yunsuanfus"
                            :key="item"
                            :label="item"
                            :value="item">
                            </el-option>
                        </el-select>
                </el-col>
                <el-col v-if="gs.append!=null && gs.append.indexOf('则')!=0" :span="6">
                        <el-input v-if="zhibiao_options[gs.zhibiao]==null" v-model="gs.value" placeholder="数值" style="margin-left:15px;margin-right:15px;"></el-input>
                        <el-select v-if="zhibiao_options[gs.zhibiao]!=null" v-model="gs.value" placeholder="数值">
                            <el-option
                            v-for="item in zhibiao_options[gs.zhibiao]"
                            :key="item"
                            :label="item"
                            :value="item">
                            </el-option>
                        </el-select>
                </el-col>
                <el-col :span="4">
                    <el-button type="danger" v-on:click="DeleteRow(index)">删除当前行</el-button>
                </el-col>
            </el-row>

        </div>
    </div>
</template>
<script>
    export default {
        data:function(){
            return {
               yunsuanfus:[
                   ">","<",">=","<=","!=","=="
               ],
               gongshis:[

               ],
               zhibiaos:[
                   "水分",
                   "杂质",
                   "品种",
                   "容重"
               ],
               zhibiao_options:{
                   "品种":[
                       "一级",
                       "二级",
                       "国产",
                       "进口"
                   ]
               },
               append_gongshi_rel:[
                   "开始",
                   "且",
                   "或",
                   "则扣重",
                   "则扣价",
                   "则拒收"
               ]
            }
        },
        computed:{
           
        },
        mounted:function(){
           
        },
        methods:{
           AddGs:function(){
               this.gongshis.push(
                   {
                       append:"且",
                       zhibiao:null,
                       rel:null,
                       value:null,
                       express:null,
                       kouzhong:null
                   }
               )
           },
           DeleteRow:function(rowIndex){
               this.gongshis.splice(rowIndex,1);
           }
        },
        beforeDestroy:function(){
            
        }
    };
</script>
<style>
.gongshi .el-select{
    width:100%;
    margin-left:15px;
    margin-right:15px;
}
</style>